package net.tp.algo.localsearch;

import java.util.Random;

/**
 * User: Trung
 * Date: 5/2/13
 * Time: 9:25 AM
 */
public class Rastrigin implements State {

    public static final double STDDEV = 0.5;
    public static Random random = new Random();

    private final double x;
    private final double y;

    public Rastrigin(double x, double y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public State step() {
        return new Rastrigin(x + STDDEV * random.nextGaussian(), y + STDDEV * random.nextGaussian());
    }

    @Override
    public double energy() {
        return x*x + y*y - Math.cos(18*x) - Math.cos(18*y) + 2;
    }

}
